

//% color="#1296db" iconWidth=50 iconHeight=40
namespace ltr390uv {
    //% block="ltr390uv init while success i2c address 0x1C" blockType="command"
    export function I2C_init(parameter: any, block: any) {
        Generator.addInclude("ltr390uvlib", `#include "DFRobot_LTR390UV.h"`);
        Generator.addObject(`ltr390obj`, `DFRobot_LTR390UV`, `ltr390(/*addr=*/LTR390UV_DEVICE_ADDR, /*pWire = */&Wire);`);
        Generator.addCode([`while(ltr390.begin() != 0){delay(1000);}`, Generator.ORDER_UNARY_POSTFIX]);
 
    }
   

    //% board="arduino,microbit"
    //% block="ltr390uv init with UART [UART] RX[RX] TX[TX]" blockType="command"
    //% UART.shadow="dropdown" UART.options="UART" 
    //% RX.shadow="dropdown" RX.options="RX" 
    //% TX.shadow="dropdown" TX.options="TX" 
    export function UART_init(parameter: any, block: any) {
        let uart=parameter.UART.code;
        let rx=parameter.RX.code;
        let tx=parameter.TX.code;
        Generator.addInclude("ltr390uvlib", `#include "DFRobot_LTR390UV.h"`);
        Generator.addInclude("softwarelib", `#include <SoftwareSerial.h>`);
        Generator.addObject(`myserial`, `SoftwareSerial`, `mySerial(/*rx =*/${rx}, /*tx =*/${tx});`,false);
        Generator.addObject(`ltr390obj`, `DFRobot_LTR390UV`, `ltr390(/*addr =*/LTR390UV_DEVICE_ADDR, /*s =*/&mySerial);`,false);
        Generator.addCode(`mySerial.begin(9600);`);
        Generator.addCode([`while(ltr390.begin() != 0){delay(1000);}`, Generator.ORDER_UNARY_POSTFIX]);
 
    }


    //% block="set sensor mearsrate to[RATE] sampling time[TIME]" blockType="command"
    //% RATE.shadow="dropdown" RATE.options="RATE"
    //% TIME.shadow="dropdown" TIME.options="TIME" 
    export function setALSOrUVSMeasRate(parameter: any, block: any) {
        let rate=parameter.RATE.code;
        let time=parameter.TIME.code;
        Generator.addCode(`ltr390.setALSOrUVSMeasRate(ltr390.${rate},ltr390.${time});`);
 
    }

    //% block="set sensor detect mode to[GAIN]" blockType="command"
    //% GAIN.shadow="dropdown" GAIN.options="GAIN" 
    export function setALSOrUVSGain(parameter: any, block: any) {
        let gain=parameter.GAIN.code;
        Generator.addCode(`ltr390.setALSOrUVSGain(ltr390.${gain});`);
 
    }
    
    //% block="Set the gain multiplier to[MODE]" blockType="command"
    //% MODE.shadow="dropdown" MODE.options="MODE" 
    export function setmode(parameter: any, block: any) {
        let mode=parameter.MODE.code;
        Generator.addCode(`ltr390.setMode(ltr390.${mode});`);
 
    }

    //% block="Get sensor [MOD] data" blockType="reporter"
    //% MOD.shadow="dropdown" MOD.options="MOD" 
    export function getData(parameter: any, block: any) {
        let mod=parameter.MOD.code;
        Generator.addCode(`ltr390.${mod}()`);
 
    }



 
}
